package com.example.net

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityComponent
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import javax.inject.Singleton

@Module//声明当前是一个Hilt模块
@InstallIn(SingletonComponent::class)//声明当前类的作用域是整个应用
object HttpHiltModel {

    @HttpClientAnnotation
    @Provides//对外暴露
    @Singleton//单例
    fun provideOkHttpClient():OkHttpClient{
        return OkHttpClientManager.createOkHttpClient()
    }
    @HttpsRetrofitAnnotation
    @Provides//对外暴露
    @Singleton//单例
    fun provideOkHttpsClient():OkHttpClient{
        return OkHttpClientManager.createOkHttpsClient()
    }
    @HttpRetrofitAnnotation
    @Provides//对外暴露
    @Singleton//单例
    fun provideOkHttpRetrofit(@HttpRetrofitAnnotation client: OkHttpClient):Retrofit{
        return RetrofitManager.getRetrofit(client)
    }
    @HttpsRetrofitAnnotation
    @Provides//对外暴露
    @Singleton//单例
    fun provideOkHttpsRetrofit(@HttpsRetrofitAnnotation client: OkHttpClient):Retrofit{
        return RetrofitManager.getRetrofit(client)
    }
}